<script type="text/javascript" src="<?php echo ThemePath(); ?>/js/jquery.blockUI.js"></script>
<section>
    <div class="container">
        <div class="row">
            <div class="span12">
                <div class="common sortingDiv">                
                    <form class="remmarginB">
                        <fieldset>
                            <div class="col">
                                <p class="sorttxt inline-block">Sort By</p>
                            </div>            
                            <div class="col">   
                                <select class="fancyselect" id="mostpopular">
                                    <option value="">Select class type</option>
                                    <option value="1">Most Popular</option>
                                    <option value="2">Most View </option>
                                </select>
                            </div>

                            <div class="col">
                                <select class="fancyselect" id="priceorder">
                                    <option value="">Select price order</option>
                                    <option value="1">Ascending Order</option>
                                    <option value="2">Descending Order</option>
                                </select>
                            </div>

                        </fieldset>
                    </form>                               
                    <div class="clear"></div>
                </div>                
            </div>
            <input type="hidden" id="current_category" >
            <input type="hidden" id="current_classcourse_type"  value="<?php echo (isset($_GET['type'])) ? $_GET['type'] : ''; ?>">
            <input type="hidden" id="current_class_for" >
            <input type="hidden" id="current_schedule" >
            <input type="hidden" id="current_schedule_post_work" >
            <div class="span3">
                <!--Show Hide Filter in Mobile View-->
                <a href="javascript:void(0);" id="filterBtn"><em class="sprite">&nbsp;</em><span>Show Filter</span></a>
                <!--End of Filter Mobile button-->
                <div class="filterBox">	                    
                    <fieldset>
                        <div class="common greenBg radius4px">
                            <div class="padding20px">
                                <h4>Location</h4>
                                <div> 
                                    <?php echo CHtml::dropDownList('location_name', '', CHtml::listData(ClassVenue::model()->findAll('status=' . SkillConfig::STATUS_ACTIVE . ' GROUP BY venue_locality'), 'id', 'venue_locality'), array('empty' => 'Select Location', 'class' => 'selectsort', 'id' => 'select_location_id')); ?>
                                </div>
                            </div>
                        </div>
                        <div class="common greenBg radius4px">
                            <div class="padding20px ">
                                <h4>Type</h4>
                                <input id="Radio5" type="radio" name="classCourseType" <?php echo (isset($_GET['type']) && $_GET['type'] == 'course') ? $checkedRadio : ''; ?> value="course" class="fancyRadio"/> <label>Courses</label>
                                <input id="Radio5" type="radio" name="classCourseType" <?php echo (isset($_GET['type']) && $_GET['type'] == 'workshop') ? $checkedRadio : ''; ?> value="workshop" class="fancyRadio"/><label>Classes & Workshops</label>
                                <input id="Radio5" type="radio" name="classCourseType" <?php echo (isset($_GET['type']) && $_GET['type'] == 'curatedclasses') ? $checkedRadio : ''; ?> value="curatedclasses" class="fancyRadio"/> <label>Curated Classes</label>
                                <div class="height1px addmarginB10 borB"></div>
                            </div>
                        </div>

                        <div class="common greenBg radius4px">
                            <div class="padding20px ">
                                <h4>Category</h4>
                                <?php
                                $categorys = Category::model()->findAll('status=' . SkillConfig::STATUS_ACTIVE);
                                foreach ($categorys as $category) {
                                    ?>
                                    <input type="checkbox" id="category_<?php echo $category->id; ?>"class="selectsort " value="<?php echo $category->id; ?>"><label><?php echo $category->name; ?></label>   
                                <?php } ?>
                                <div class="height1px addmarginB10 borB"></div>			
                            </div>
                        </div>

                        <div class="common greenBg radius4px">
                            <div class="padding20px ">
                                <h4>Functionality</h4>
                                <input type="checkbox"  name="functionality" class="selectsort" id="schedule_1" <?php echo (isset($_GET['searchtype']) && $_GET['searchtype'] == SEARCH_TYPE_WEEKEND) ? "checked=checked" : ''; ?> value="<?php echo SEARCH_CLASS_WEEKEND_SET_DAY_SESSION; ?>">
                                <label><?php echo SEARCH_CLASS_WEEKEND; ?></label>
                                <input type="checkbox"  name="functionality" class="selectsort" id="schedule_2" <?php echo (isset($_GET['searchtype']) && $_GET['searchtype'] == SEARCH_TYPE_KIDS) ? "checked=checked" : ''; ?> value="<?php echo SEARCH_CLASS_KIDS_SET_DAY_SESSION; ?>">
                                <label><?php echo SEARCH_CLASS_KIDS_CLASS; ?></label>
                                <input type="checkbox"  name="functionality" class="selectsort" id="postwork_3" <?php echo (isset($_GET['searchtype']) && $_GET['searchtype'] == SEARCH_TYPE_POST_WORK) ? "checked=checked" : ''; ?> value="<?php echo SEARCH_CLASS_POST_WORK_VAL; ?>">
                                <label><?php echo SEARCH_CLASS_POST_WORK; ?></label>
                                <div class="height1px addmarginB10 borB"></div>
                            </div>
                        </div>

                        <div class="common greenBg radius4px">
                            <div class="padding20px">
                                <h4>Price</h4>
                                <input type="text" class="field"id="amount_range" >
                                <div id="slider-range"></div>

                            </div>
                        </div>
                        <div class="common greenBg radius4px">
                            <div class="padding20px">
                                <h4>Date</h4>                                  
                                <input type="text" name="from" class="field date-field " placeholder="From" id="from"  onpaste="return false;">
                                <input type="text"  name="to" class="field date-field " placeholder="To" id="to"  onpaste="return false;">

                            </div>
                        </div>

                    </fieldset>

                </div>
            </div> 

            <div class="span9">
                <div class="row">
                    <div class="clsListing">
                        <ul>
                            <?php
                            /* here is class course list start */
                            if (isset($_GET['authKey'])) {
                                $this->widget('zii.widgets.CListView', array(
                                    'dataProvider' => $dataProvider,
                                    'id' => 'ajaxListView',
                                    'summaryText' => '',
                                    'itemView' => '//courses/_runningClassCoursedataprovider',
                                ));
                            } elseif (isset($pagetype) && ($pagetype == 'LiterallyEndingClasses')) {
                                $this->widget('zii.widgets.CListView', array(
                                    'dataProvider' => $dataProvider,
                                    'id' => 'ajaxListView',
                                    'summaryText' => '',
                                    'itemView' => '//classes/_literalendingtommorowdataprovider',
                                ));
                            } elseif (isset($pagetype) && ($pagetype == 'searchClass')) {
                                $this->widget('zii.widgets.CListView', array(
                                    'dataProvider' => $dataProvider,
                                    'id' => 'ajaxListView',
                                    'summaryText' => '',
                                    'itemView' => '//classes/_search_classcourse_data_provider',
                                ));
                            } else {
                                if ($activeClass[1] != 'course') {
                                    $this->widget('zii.widgets.CListView', array(
                                        'dataProvider' => $dataProvider,
                                        'id' => 'ajaxListView',
                                        'summaryText' => '',
                                        'itemView' => '/classes/_categoryByClassList',
                                    ));
                                } else {

                                    $this->widget('zii.widgets.CListView', array(
                                        'dataProvider' => $dataProvider,
                                        'id' => 'ajaxListView',
                                        'summaryText' => '',
                                        'itemView' => '//courses/_categoryByCourseList',
                                    ));
                                }
                            }
                            ?>                         
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<div class="padding20px"></div>
<?php /* Literally Ending tomorrow Slider */ ?>
<?php
$allClassCourseInfo = array();
$classDetails = literalEndingTommorow('', '', '');
$courseDetails = runningCurrentCoursesByUser('', '', ''); //Null parameter means these value $profiles, $userType, $getValue)
$allClassCourseInfo = array_merge($classDetails, $courseDetails);
usort($allClassCourseInfo, 'date_compare');
$validatedata = literalendingtommorowValiadte($allClassCourseInfo);
if (!empty($validatedata)) {
    $this->renderPartial('/classes/literallyEndingtomorrow', array('allClassCourseInfo' => $allClassCourseInfo));
}
?>
<script>
    $(function() {
        $( "#slider-range" ).slider({
            range: true,
            min: 0,
            max: 15000,
            values: [ 0, 15000 ],
            slide: function( event, ui ) {
                $( "#amount_range" ).val( "" + ui.values[ 0 ] + " - " + ui.values[ 1 ] );
            }
            
        });
        
        $( "#amount_range" ).val( "" + $( "#slider-range" ).slider( "values", 0 ) +
            " - " + $( "#slider-range" ).slider( "values", 1 ) );
    });
    $(function() {
        $( "#slider-range" ).slider({
            change:function() { getMinPriceMaxPrice(); }
        });
    });

</script>
<script>
    $(function() {
        $( "#from" ).datepicker({            
            defaultDate: "+1w",
            changeMonth: true,           
            dateFormat: 'yy-mm-dd',
            onClose: function( selectedDate ) {              
                $( "#to" ).datepicker( "option", "minDate", selectedDate );
                if($( "#from" ).val()!='' && $( "#to" ).val()!='' )
                    getAjaxListUpdate('ajaxUpdateTimeout','ajaxRequest');
            }
        });
        $( "#to" ).datepicker({
            defaultDate: "+1w",
            changeMonth: true,           
            dateFormat: 'yy-mm-dd',
            onClose: function( selectedDate ) {
                $( "#from" ).datepicker( "option", "maxDate", selectedDate );               
                if($( "#from" ).val()!='' && $( "#to" ).val()!='' )
                    getAjaxListUpdate('ajaxUpdateTimeout','ajaxRequest');
            }
        });
    });
</script>
<?php
Yii::app()->clientScript->registerScript('search', "var ajaxUpdateTimeout;
    var ajaxRequest;    
    $('.selectsort').fancyfields({
            onCheckboxChange: function (input, isChecked) {
                var array = input.attr('id').split('_');
                var allVals = [];
                var allClassFor = [];
                 var allscheduleFor = [];
                if (isChecked){ 
                    if(array[0]=='classfor'){ 
                        $('#classfor_' + array[1]).addClass('classFor');
                        $('.classFor').each(function() {
                            allClassFor.push($(this).val()); });
                        $('#current_class_for').val(allClassFor);
                    }
                    if(array[0]=='postwork'){                       
                        $('#current_schedule_post_work').val(input.val());
                    }
                    
                    if(array[0]=='schedule'){ 
                        $('#schedule_' + array[1]).addClass('scheduleFor');
                        $('.scheduleFor').each(function() {
                            allscheduleFor.push($(this).val()); });
                        $('#current_schedule').val(allscheduleFor);
                    }
                    if(array[0]=='category'){
                        $('#category_' + array[1]).addClass('categoryCheckBox');
                        $('.categoryCheckBox').each(function() {
                            allVals.push($(this).val());    });
                        $('#current_category').val(allVals);
                    } } else {
                    if(array[0]=='postwork'){                       
                        $('#current_schedule_post_work').val('');
                    }
                    if(array[0]=='classfor'){
                        $('#classfor_' + array[1]).removeClass('classFor');
                        $('.classFor').each(function() {
                            allClassFor.push($(this).val()); });
                        $('#current_class_for').val(allClassFor);
                    }
                     if(array[0]=='schedule'){ 
                        $('#schedule_' + array[1]).removeClass('scheduleFor');
                        $('.scheduleFor').each(function() {
                            allscheduleFor.push($(this).val()); });
                        $('#current_schedule').val(allscheduleFor);
                    }
                    if(array[0]=='category'){
                        $('#category_' + array[1]).removeClass('categoryCheckBox');
                        $('.categoryCheckBox').each(function() {
                            allVals.push($(this).val());});
                        $('#current_category').val(allVals);
                    }  
                } 
                getAjaxListUpdate(ajaxUpdateTimeout,ajaxRequest);
            }
  
        });
        $('#select_location_id').fancyfields('bind','onSelectChange',function(){
         getAjaxListUpdate(ajaxUpdateTimeout,ajaxRequest);
  });
 "
)
?>

<script type="text/javascript">
    jQuery(document).ready(function() {        
        $(".fancyselect").fancyfields({
            onSelectChange: function (input,text,val){
                getAjaxListUpdate('ajaxUpdateTimeout','ajaxRequest');
            }
        }); 
        $(".fancyRadio").fancyfields({
            onRadioChange: function (input){
                var value=input.val();
                $("#current_classcourse_type").val(value);
                if(value=='course'){
                    $(".catList li" ).removeClass("active");
                    $(".catList li" ).eq(0).addClass("active");}
                if(value=='workshop'){
                    $(".catList li" ).removeClass("active");
                    $(".catList li" ).eq(1).addClass("active");}
                if(value=='curatedclasses'){
                    $(".catList li" ).removeClass("active");
                    $(".catList li" ).eq(2).addClass("active");
                }
                getAjaxListUpdate('ajaxUpdateTimeout','ajaxRequest');
            }
        }); 
        //        $(".customSBDemo").fancyfields({ customScrollBar: false });
        //        $("#demoReset").click(function () {
        //            $(".flatui").fancyfields("reset");			
        //            $(".customSBDemo").fancyfields("reset");
        //        });
        
    });
    function getMinPriceMaxPrice(){
        getAjaxListUpdate('ajaxUpdateTimeout','ajaxRequest');}
    function getAjaxListUpdate(ajaxUpdateTimeout,ajaxRequest){
        var  postwork=$('#current_schedule_post_work').val();
        var dateFrom=$("#from").val();
        var dateto=$("#to").val();
        var priceorder=$("#priceorder").val();
        var mostpopular=$("#mostpopular").val();      
        var type=$("#current_classcourse_type").val();
        var amountRange=$("#amount_range").val();
        var location=$("#select_location_id").val();
        var schedule=$("#current_schedule").val();
        var tragetAudience=$('#current_class_for').val();
        var categoryId=$('#current_category').val();
        var sort_respond_unrespond=$('#sort_respond_unrespond').val();
        var sort_converted_unconverted=$('#sort_converted_unconverted').val();
        ajaxRequest = 'category='+categoryId+'&tragetAudience=' + tragetAudience+'&location=' + location+'&amountRange='+amountRange+'&scheduleId='+schedule+'&dateFrom='+dateFrom+'&dateto='+dateto+'&type='+type+'&postwork='+postwork+'&priceorder='+priceorder+'&mostpopular='+mostpopular;
        clearTimeout(ajaxUpdateTimeout);
        ajaxUpdateTimeout = setTimeout(function () {
            imageloding();
            $.fn.yiiListView.update(
            'ajaxListView',
            {data: ajaxRequest}
            
        )},
        
        100);
        $(document).ajaxStop($.unblockUI); }
</script>


